package com.fly.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * 切片
 */
@Aspect
@Component
public class TimeAspect {
    // 包围
    @Around("execution(* com.fly.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint point) throws Throwable {
        System.out.println("time aspect start");
        for (Object arg : point.getArgs()) {
            System.out.println("arg = " + arg);
        }
        long startTime = System.nanoTime();
        Object o = point.proceed();
        System.out.println("耗时:" + (System.nanoTime() - startTime) / 1000000000.0 + "s");
        System.out.println("time aspect end");
        return o;
    }
}
